// myPages/orderTeacher/orderTeacher.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var user = require('../../services/user.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    orderInfo: [] //订单信息
  },
  onChange(event) {
    wx.showToast({
      title: `切换到标签 ${event.detail.index + 1}`,
      icon: 'none'
    });
  },

  //查询用户订单信息
  getOrderInfo() {
    var that = this;
    var userId = wx.getStorageSync('userInfo').id //获取老师id
    let searchCondition = {
      pageSize: 5,
      pageNum: 1,
      conditionList: [],
      sort: {}
    };
    let condition1 = {
      operator: 1,
      code: 'toUserId',
      value: userId, //老师ID
      type: 'Number'
    };
    searchCondition.conditionList.push(condition1)
    console.log(searchCondition)

    util.request(api.OrderInfo, searchCondition, 'POST', true).then(function(res) {
      if (res.code === 200) {
        res.result.forEach((item, index, arr) => {
          item.statusTxT = util.getOrderStatus(item.status)
        })
        that.setData({
          orderInfo: res.result
        })
      }else{
        wx.showToast({
          title: res.message,
          icon: 'none'
        });
      }
    });
  },

  //查看订单
  gotoOrder: function(e) {
    wx.navigateTo({
      url: '../../myPages/process/process?userOrderId=' + e.currentTarget.dataset.id,
    })
  },
  //查看订单详情
  gotoOrderInfo(e) {
    let status = e.currentTarget.dataset.status
    let id = e.currentTarget.dataset.id
    if (status == 2 || status == 4 || status == 5) {
      wx.navigateTo({
        url: '../../myPages/process/process?userOrderId=' + id,
      })
    }else{
      wx.navigateTo({
        url: '../../myPages/orderInfo/orderInfo?userOrderId=' + id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //接收传过来的参数
    console.log('接收到的userId为：' + options.userid);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getOrderInfo();
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})